package org.framework.factory;

import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.beans.factory.FactoryBean;

import java.util.Map;

/**
 * @ClassName MessageExchangeFactoryBean
 * @Description
 * @Author RayLiang
 * @Date 2022/12/12 15:55
 * @Version 1.0
 **/
public class MessageExchangeFactoryBean implements FactoryBean<Exchange> {

    private String exchangeName;
    private String type;
    private boolean durable;
    private boolean autoDelelte;
    private int order;

    public MessageExchangeFactoryBean(String exchangeName, String type, boolean durable, boolean autoDelete,int order) {
        this.exchangeName = exchangeName;
        this.type = type;
        this.durable = durable;
        this.autoDelelte = autoDelete;
        this.order = order;
    }


    @Override
    public Exchange getObject() {
        Exchange exchange = null;
        switch (this.type) {
            case ExchangeTypes.DIRECT:
                exchange = new DirectExchange(this.exchangeName, this.durable, this.autoDelelte);
                break;
            case ExchangeTypes.FANOUT:
                exchange = new FanoutExchange(this.exchangeName, this.durable, this.autoDelelte);
                break;
            default:
        }
        return exchange;
    }

    @Override
    public Class<?> getObjectType() {
        return Exchange.class;
    }
}
